package com.qz.mos.filter;

import com.qz.mos.Mos2Application;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
//@Configuration
//@Component
@Slf4j
public class LogFilter implements GlobalFilter, Ordered {
    @Override
    public Mono <Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 前置过滤器
        log.info( "url:{}", exchange.getRequest().getPath());
        return chain.filter( exchange ).then(
                Mono.fromRunnable( () -> {
                            // 后置过滤器
                    Mos2Application.restDataThreadLocal.remove();
                    log.info( "请求结束处理" );
                        }
                ) );
    }

    /**
     * 设定过滤器的优先级，值越小则优先级越高
     *
     * @return
     */
    @Override
    public int getOrder() {
        return 0;
    }


}